<?php
class Apps_View_Helper_SerializeParam extends Zend_View_Helper_Abstract {
    CONST DELIMITER = '|';

	public function serializeParam($field, $showField=true, $delimiter=null) {
        $rq = Zend_Controller_Front::getInstance()->getRequest();
        $d  = $rq->getParam($field);

        $xhtml = '';
        if(is_array($d)) {
            if(null === $delimiter) { $delimiter = self::DELIMITER; }
            $xhtml = implode($delimiter, $d);
        } else if(is_string($d)) {
            $xhtml = $d;
        }

        if($showField) {
            $xhtml = $field . '=' . $xhtml;
        }

        return $xhtml;
	}
	public static function deserializeParam($field, $delimiter=null) {
	    $rq = Zend_Controller_Front::getInstance()->getRequest();

	    if(null === $delimiter) { $delimiter = self::DELIMITER; }

	    $d  = $rq->getParam($field);
	    $d  = explode($delimiter, $d);
	    if(count($d) < 2) {
	        $d = $d[0];
	    }
        return $d;
	}
}
